<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
		<div id="mainownservice">
			<h3><?php echo JText::_('OWNSERVICE_APPROVAL_TRANSFERRED'); ?></h3>
			<hr />
			<script language="javascript" type="text/javascript">
			<!--
				function submitbutton(pressbutton)
				{
					var form = document.adminForm;
					if (pressbutton == 'requestapproval') {
						submitform( pressbutton );
						return;
					}
					if(form.transfer_id.value == '') {
						alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_STAFF_TRANSFER', true ); ?>" );
					}else {
						submitform( pressbutton );
					}

				}
			//-->
		</script>
			<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm">
				<table cellspacing="10" cellpadding="0" border="0" width="100%">
				<tr>
					<td>
						<fieldset>
							<legend><?php echo JText::_('OWNSERVICE_STAFF_TRANSFER'); ?></legend>
							<table class="admintable">
							<tr>
								<td>
									<span class="red">*</span> <?php echo $this->lists['receiving']; ?>
								</td>
							</tr>
							</table>
						</fieldset>
					</td>
				</tr>
				<tr>
					<td>
						<table class="adminlist" cellspacing="10" cellpadding="0" border="0" width="100%">
							<thead>
								<tr>
									<th><?php echo JText::_( 'OWNSERVICE_RECEIVER_NO' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_ACCOUNT_NO' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_BANK_NAME' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_BRANCH_CITY' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_USER' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_TRANSFER_ON' ); ?></th>
									<th><?php echo JText::_( 'OWNSERVICE_AMOUNT_TRANSFER' ); ?><br />(AUD)</th>
									<th><?php echo JText::_( 'OWNSERVICE_RATE' ); ?><br />(THB)</th>
									<th><?php echo JText::_( 'OWNSERVICE_TOTAL_EXCHANGE' ); ?><br />(THB)</th>
								</tr>
							</thead>
							<tbody>
								<?php
								$priceformat = OwnserviceHelper::getParams('price_format', '#,###.##');
								$dateformat  = OwnserviceHelper::getParams('date_format', '%d/%m/%Y');
								$k=0;
								$sum_amount	= 0;
								$sum_rate	 	= 0;
								$sum_total		= 0;
								foreach ($this->rows as $row) :
									if (in_array($row->id, $this->cid)) :
								?>
								<tr class="<?php echo "row$k"; ?>">
									<td>
										<input type="hidden" name="cid[]" value="<?php echo $row->id; ?>" />
										<?php echo $row->invoice; ?>
									</td>
									<td><?php echo OwnserviceHelper::accountFormat($row->account); ?></td>
									<td>
										<?php if($row->abankname=='other'): ?>
											<?php echo $row->bank_other; ?>
										<?php else: ?>
											<?php echo $row->abankname; ?>
										<?php endif; ?>
									</td>
									<td><?php echo $row->branch_city; ?></td>
									<td><?php echo $row->username; ?></td>
									<td align="center"><?php echo JHTML::_('date', $row->requested_date, $dateformat); ?></td>
									<td align="center">
										<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?>
										<?php $sum_amount = $sum_amount + $row->amount; ?>
									</td>
									<td align="right">
										<?php
											$color = '';
											if($row->extrarate > 0.00 ) {
												$color = 'red';
											} else if($row->extrarate < 0.00) {
												$color = 'green';
											}
										?>
										<?php if(!$row->iscore): ?>
										<div style="border-bottom: 1px solid;">
											<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th); ?> THB
										</div>
										<?php endif; ?>
										<div>
											<span class ="<?php echo $color; ?>">
											<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate); ?>
											</span>
											<?php echo $row->rate_code; ?> 
										</div>
									</td>
									<td align="right">
										<?php if(!$row->iscore): ?>
										<div style="border-bottom: 1px solid;">
											<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
											<?php $sum_total = $sum_total + $row->total_th; ?>
										</div>
										<?php else: ?>
											<?php
												if($row->extratotal > 0.00 ){
													$sum_total = $sum_total + $row->extratotal;	
												} else {
													$sum_total = $sum_total + ( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee));  
												}
											?>
										<?php endif; ?>
										<div>
											<span class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
												<?php 
													if($row->extratotal > 0.00) {
														echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal);
													} else {
														echo OwnserviceHelper::moneyFormat($priceformat,( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))); 
													}
													?>
											</span> <?php echo $row->rate_code; ?>
										</div>
									</td>
								</tr>
								<?php
									endif;
									$k = 1 - $k;
								endforeach;
								?>
								<tr>
									<td colspan="6" align="right">
										<strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong>
									</td>
									<td align="center" style="font-weight: bold;">
										<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_amount); ?>
									</td>
									<td align="right">
									</td>
									<td align="right" style="font-weight: bold;">
										<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_total). ' THB'; ?>
									</td>
								</tr>
							</tbody>
						</table>
					</td>
				</tr>
			</table>
			<div style="text-align:center; margin-top:5px;">
				<input type="button" name="ok" onclick="javascript:showdialog();" value="<?php echo JText::_('OWNSERVICE_OK'); ?>" />
				<input type="button" name="cancel" onclick="javascript:submitbutton('requestapproval');" value="<?php echo JText::_('OWNSERVICE_CANCEL');?>" />
			</div>
			<input type="hidden" name="option" value="com_ownservice" />
			<input type="hidden" name="task" value="" />
			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
			<input type="hidden" name="controller" value="transaction" />
			<input type="hidden" name="view" value="transactions" />
			<?php echo JHTML::_( 'form.token' ); ?>
			</form>
	</div>
</div>
<!-- dialog -->
<div id="dialog" title="<?php echo JText::_('OWNSERVICE_CONFIRM').' '.JText::_('OWNSERVICE_APPROVAL_TRANSFERRED'); ?>" style="display: none; text-align:center;">
	<div style="margin-top: 30px;">
		<input type="button" name="confirm" onclick="javascript:submitbutton('transfer');" value="<?php echo JText::_('OWNSERVICE_CONFIRM'); ?>" /> 
		<input type="button" name="confirm" onclick="javascript:submitbutton('downloadapprovaltransferred');" value="<?php echo JText::_('OWNSERVICE_DOWNLOAD'); ?>" />
	</div>
</div>